<?php 
class loginAction extends action{
	public function index(){
		$GLOBALS['smarty']->display('login.html');
	}
	
	public function login(){
		$name = empty($_POST['username'])?null:$_POST['username'];
		$pass = empty($_POST['password'])?null:md5($_POST['password']);
		$remember = empty($_POST['notlogin'])?false:true;
		
		$name = empty($name)?isset($_COOKIE['admin'])?$_COOKIE['admin']:null:$name;
		$pass = empty($pass)?isset($_COOKIE['admin_pass'])?$_COOKIE['admin_pass']:null:$pass;
		
		I('admin');
		$oAdminUser = new admin();
		$admin = $oAdminUser->getAdmin($name, $pass);
		if($admin){
			$_SESSION['admin_id'] = $admin['id'];
			$_SESSION['admin_name'] = $admin['name'];
			$_SESSION['purview'] = $admin['purview'];
			if($remember){
				set_cookie('admin', $name);
				set_cookie('admin_pass', $pass);
			}
			$this->direct('index');
		}
		else{
			$this->makeError('该管理员不存在！');
		}
	}
	
	public function logout(){
		$_SESSION['admin_id'] = null;
		$_SESSION['admin_name'] = null;
		$_SESSION['purview'] = null;
		set_cookie('admin', '');
		set_cookie('admin_pass', '');
		$this->direct('index');
	}
}
?>